<template>
	<div>
		<Row>
			
			<Col class="p-1" :xs="24" :sm="24" :md="12" :lg="8" :xl="6" :xxl="4">
			<Input class="w-100" v-model="searchName" placeholder="请输入部门名称" />
			</Col>

		</Row>
		<Row class="">
			<div class="d-flex justify-content-between align-items-center">
			<Button class="m-1" type="error" shape="circle" @click="newDept" icon="md-add">新增</Button>
			<Button class="m-1 " type="primary" shape="circle" @click="searchs" icon="ios-search">查询</Button>
			</div>
		</Row>
		<div class="mt-1 d-none d-xl-block">
			<Table border :class="'m-1'" :columns="tableInfo.columnInfo" :data="tableInfo.data">
				<template slot-scope="{ row, index }" slot="action">
					<Button type="primary" size="small" class="mr-2" @click="show(row.deptId)">详细</Button>
					<Button type="error" size="small" @click="remove(row.deptId)">删除</Button>
				</template>
			</Table>
		</div>
		<div class="mt-1 d-xl-none">
			<Row>
				<Col class="p-1" v-for="(dept, index) in tableInfo.data" :xs="24" :sm="24" :md="12" :lg="12">
				<div class="text-xss rounded shadow text-secondary p-1 bg-light">
					<div class="p-1 d-flex justify-content-between">
						<span>部门编号 </span><span>{{dept.deptId}}</span>
					</div>
					<div class="p-1 d-flex justify-content-between">
						<span>部门名称 </span><span>{{dept.name}}</span>
					</div>
					<div class="p-1 d-flex justify-content-between">
						<span>职位数量 </span><span>{{dept.jobNum}}</span>
					</div>
					<div class="p-1 d-flex justify-content-between">
						<span>员工数量 </span><span>{{dept.empNum}}</span>
					</div>
					<div class="p-1 d-flex justify-content-between">
						<span>流程数量 </span><span>{{dept.flowNum}}</span>
					</div>

					<div class="p-1 d-flex justify-content-end">
						<Button class="text-xss" type="error" size="small" @click="remove(dept.deptId)">删除</Button>
						<Button class="text-xss ml-2" type="primary" size="small" @click="show(dept.deptId)">详细</Button>

					</div>
				</div>
				</Col>
			</Row>
		</div>
		<div>
			<Page class="text-right mt-3" :page-size="tableInfo.pageSize" @on-change="pageSearch"
				:total="tableInfo.total" />
		</div>

	</div>
</template>
<script>
	export default {
		data() {
			return {
				searchName: "",

				tableInfo: {
					currentPage: 1,
					total: 0,
					pageSize: 10,
					columnInfo: [{
							title: "部门编号",
							key: "deptId",
							width: 100
							
						},
						{
							title: "部门名称",
							key: "name",
							
						},

						{
							title: "职位数量",
							key: "jobNum",
							
						},
						{
							title: "员工数量",
							key: "empNum",
						
						},
						{
							title: "流程数量",
							key: "flowNum",
							
						},
						{
							title: "操作",
							slot: 'action',
							width: 150

						}
					],
					data: []
				}
			}
		},
		methods: {
			init: function() {
				this.tableInfo.currentPage = 0;
				this.search();
			},
			newDept: function() {
				this.$router.detail.open({
					name: "dept_new",
				});
			},


			show: function(deptId) {
				console.log(deptId)
				this.$router.push({
					path: "/dept/info?deptId=" + deptId
				
				});
			},
		
		
			remove: function(deptId) {

				this.message.confirm({
					title: "删除提示",
					content: "即将删除部门，确定吗？",
					onOk: () => {
						this.http.delete({
							url: "/dept/info",
							param: {
								deptId
							}
						}).then(data => {

							this.search();
						});
					},
					onCancel: () => {
						this.message.info('操作已取消');
					}
				});
			},
			searchs: function() {
				this.tableInfo.currentPage = 1;
				this.search();
			},
			search: function() {
				this.http.get({
					url: "/dept/page",
					param: {
						current: this.tableInfo.currentPage,
						size:this.tableInfo.pageSize,
						name: this.searchName,

					}
				}).then(data => {
					this.tableInfo.currentPage = data.current;
					this.tableInfo.total = data.total;
					this.tableInfo.pageSize = data.size;
					this.tableInfo.data = data.records;
				});
			},
			pageSearch: function(changedPage) {
				this.tableInfo.currentPage = changedPage;
				this.search();
			}
		},
		created: function() {
			this.init();
		}

	}
</script>

</style>
